package com.netcracker.training.automonic.parser;

import com.netcracker.training.automonic.dao.entities.Site;

/**
 * Abstract parser. All concrete parsers must implement this interface.
 * 
 * @author Vadim Gidulyan
 *
 */
public interface Parser
{

	/**
	 * Initializes parser with specified site.
	 * 
	 * <p>In this method parser might prepare all resources that it needs 
	 * to work, such as DAO, data for parsing, parsing templates etc.</p>
	 * 
	 * @param site site for parsing
	 * 
	 * @see Site
	 */
	void init(Site site);
	
	/**
	 * {@link Parser#init(Site)}
	 * 
	 * @param sitename name of site
	 */
	void init(String sitename);
	
	/**
	 * Preparing object for operations with it.
	 * 
	 * @return <ul><li><code>true</code> if object prepared</li>
	 *             <li><code>false</code> if there are no objects</li></ul>
	 */
	boolean nextObject();
	
	/**
	 * Checks if object exists in DB or it is a new object.
	 * 
	 * @return <ul><li><code>true</code> if object exists in DB</li>
	 *             <li><code>false</code> if it is a new object</li></ul>
	 * @see #createObject()
	 */
	boolean isObjectExists();
	
	/**
	 * Saves object to DB.
	 * 
	 * <p>Usually used if need to save a new object to DB.</p>
	 * 
	 * @see #isObjectExists()
	 */
	void createObject();
	
	/**
	 * Checks if object has all attributes.
	 * 
	 * <p>Recommend to use parsing templates to keep an eye on attribute 
	 * updates.</p>
	 * 
	 * @return <ul><li><code>true</code> if object has all attributes</li>
	 *             <li><code>false</code> otherwise</li></ul>
	 * 
	 * @see #fillAttributes()
	 */
	boolean checkAttributes();
	
	/**
	 * Fills object attributes.
	 * 
	 * <p>Recommend to use parsing templates to update object attributes.</p>
	 * 
	 * @see #checkAttributes()
	 */
	void fillAttributes();
	
	/**
	 * Obtain statistics for current object and saves it to DB.
	 * 
	 * <p>Recommend to use parsing templates to obtain object statistics.</p>
	 */
	void obtainStatistics();

}
